<!doctype html>
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
<title>绑定申请</title>
<link href="../css/style.css" rel="stylesheet" type="text/css">
<link href="../css/126style.css" rel="stylesheet" type="text/css">

<script src="../js/jquery-1.4.4.min.js"   type="text/javascript" ></script>
<script type="text/javascript" src="../js/header&footer.js"></script>
<script src="../js/utils.js" type="text/javascript"></script>
<script src="../js/formValidator-4.1.1.js" type="text/javascript" charset="UTF-8"></script>
<script src="../js/formValidatorRegex.js" type="text/javascript" charset="UTF-8"></script>
<script src="../js/theme.js" type="text/javascript" charset="UTF-8"></script>
<script src="../js/check.js" type="text/javascript" charset="UTF-8"></script>
<script type="text/javascript">
// 全局变量
var _shopId;
var _openId;

$(function(){
	// 从url 中解析 shopId 和 openId
	var paramStr=location.search;
	_openId = getWxParameter("openId",paramStr);
	_shopId = getWxParameter("shopId",paramStr);
	//初始化校验
	initValidate();
});

/**
 * 初始化校验
 */
function initValidate() {
	$.formValidator.initConfig({
		submitOnce : true,
		formID : "registerForm",
		onError : function(msg) {
			alert(msg);
		},
		submitAfterAjaxPrompt : '有数据正在异步验证，请稍等...'
	});	
   $("#mp").formValidator({
		onShow : "请输入手机号码",
		onFocus : "手机的长度必须是11位",
		onCorrect : "手机合法"
	}).inputValidator({
		min : 11,
		max : 11,
		onError : "手机号码必须为11位"
	}).regexValidator({
		regExp : "mobile",
		dataType : "enum",
		onError : "手机的格式不正确"
	});
	$("#custName").formValidator({
		onShowFixText : "请输入姓名",
		onShow : "请输入姓名称",
		onFocus : "姓名不能为空",
		onCorrect : "正确"
	}).inputValidator({
		min : 1,
		onError : "姓名不能为空"
	}).regexValidator({
		regExp : "notempty",
		dataType : "enum",
		onError : "姓名不能为空"
	});
//	$("#IDNumber").formValidator({ajax:true,onShow:"请输入15或18位的身份证",onFocus:"输入15或18位的身份证",onCorrect:"输入正确"}).functionValidator({fun:isCardID});
}

/**
 * 注册
 */
function postRegister() {
	if(!$.formValidator.pageIsValid()) return false;
	var mp = $("#mp").val();
	var custName = $("#custName").val();
	var sex = $('input[name="gender"]:checked').val();
	var IDNumber = $("#IDNumber").val();
	var head = ["custName", "mp", "sex", "shopId", "IDNumber", "openId"];
	var data = [custName, mp, sex, _shopId, IDNumber, _openId];
	var result={
		'head':head,
		'data':data
	};
	var jsonData = JSON.stringify(result);
	$.post("../../custMember/insert/BD", {
		'shopId':_shopId,'openId':_openId,'name':custName,'mp':mp
	
	}, function(data) {
		if(IsEmpty(data)){
			alert('绑定失败！');
			return;
		}
		var dt = JSON.parse(data);
		if (dt.state == 0) {
			/* var noM = getHeadIndexValue(0, dt, "noInfo");
			if(IsNotEmpty(noM)&&noM==1){
				var duty = _findInfo("../../user/find/userByDutyId", {'dutyId':80})
				if(IsNotEmpty(duty)&&duty.state==0){
					var htm="尊敬的用户，我们未找到您在我店的档案信息，如有疑问请联系客服经理："+getHtmlString(getHeadIndexValue(0, duty, "Name"))+"，手机号："+getHtmlString(getHeadIndexValue(0, duty, "mp"));
					alert(htm)
				}
			}else{ */
			alert("绑定成功");
				window.location.href="../../html/member.html?openId="+_openId+"&shopId="+_shopId
			
		} else {
			alert(dt.msg);
		}
	}); 
}
</script>
</head>
<body>
<div class="wrapper">
    <div class="placeTit">申请入会</div>
    <div class="container">
        <form id="registerForm" name="registerForm" method="post">
        <div class="person">
            姓名<span class="red">*</span><br>
            <input id="custName" name="custName" type="text" class="txt">
        </div>
        <div id="custNameTip"></div>
        <div class="person">
            性别<span class="red">*</span>：<label><input type="radio"  name="gender" value="0" checked="checked"> 男</label>&nbsp;&nbsp;&nbsp;&nbsp;<label><input type="radio"  name="gender" value="1"> 女</label>
        </div>
        <div class="person">
            手机号<span class="red">*</span><br>
            <input id="mp" name="mp" type="text" class="txt">
        </div>
        <div id="mpTip"></div>
        <div class="person">
            身份证号<br>
            <input id="IDNumber" name="IDNumber" type="text" class="txt">
        </div>
        <div id="IDNumberTip"></div> 
        <div class="give">
            <input type="button" onclick="postRegister()" value="提交申请">
        </div>
        </form>
    </div>
</div>
</body>
</html>
